package com.wzx.user.controller;

import com.wzx.common.exception.LeadNewsException;
import com.wzx.common.pojo.resp.Result;
import com.wzx.user.dto.RelationDto;
import com.wzx.user.pojo.Relation;
import com.wzx.user.service.RelationService;
import com.wzx.user.vo.GroupChangeRemarkVo;
import com.wzx.user.vo.RelationVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author wzx
 * @version 1.0
 * @date 2022/7/31 - 15:36
 * @description 关系管理
 */
@Slf4j
@RestController
@RequestMapping("/relation")
@Api(tags = "关系管理")
public class RelationController {

    @Autowired
    private RelationService relationService;

    @GetMapping("/getRelationList")
    public Result<List<RelationDto>> getRelationList(Integer userId, Integer relationType) {
        List<RelationDto> relationList = relationService.getRelationList(userId, relationType);
        return Result.ok(relationList);
    }

    @PostMapping("/getRelationListBySearch")
    public Result<List<RelationDto>> getRelationListBySearch(@RequestBody RelationVo relationVo) {
        List<RelationDto> relationList = relationService.getRelationListBySearch(relationVo);
        return Result.ok(relationList);
    }

    @GetMapping("/queryRelationState")
    public Result<Relation> queryRelationState(Integer userId, Integer friendId) {
        Relation relationList = relationService.queryRelationState(userId, friendId);
        return Result.ok(relationList);
    }

    @GetMapping("/changeState")
    public Result changeState(@RequestBody Relation relation) {
        relationService.changeState(relation);
        return Result.ok();
    }

    @ApiOperation(value = "查询用户备注")
    @PostMapping("/queryFriendRemarks")
    public Result queryFriendRemarks(@RequestBody Relation relation) throws LeadNewsException {
        String friendRemarks = relationService.queryFriendRemarks(relation);
        return Result.ok(friendRemarks);
    }

    @ApiOperation(value = "修改用户备注")
    @PostMapping("/updateFriendRemarks")
    public Result<String> updateFriendRemarks(@RequestBody Relation relation) {
        String friendRemarks  = relationService.updateFriendRemarks(relation);
        return Result.ok(friendRemarks);
    }

    @ApiOperation(value = "删除好友")
    @PostMapping("/deleteFriendRemarks")
    public Result deleteFriendRemarks(@RequestBody Relation relation) throws LeadNewsException {
        relationService.deleteFriendRemarks(relation);
        return Result.ok();
    }

    @ApiOperation(value = "修改用户在群聊中的备注")
    @PostMapping("/changeRemarksByGroup")
    public Result changeRemarksByGroup(@RequestBody GroupChangeRemarkVo groupChangeRemarkVo) throws LeadNewsException {
        relationService.changeRemarksByGroup(groupChangeRemarkVo);
        return Result.ok();
    }


    @ApiOperation(value = "查询是否建立关系")
    @PostMapping("/queryIsRelation")
    public Result queryIsRelation(Integer userId, Integer friendId) throws LeadNewsException {
        Boolean b = relationService.queryIsRelation(userId, friendId);
        return Result.ok(b);
    }

    @ApiOperation(value = "将用户加入黑名单")
    @GetMapping("/addBlackUser")
    public Result addBlackUser(Integer userId, Integer friendId, String changeType) throws LeadNewsException {
        relationService.addBlackUser(userId, friendId, changeType);
        return Result.ok();
    }

    @ApiOperation(value = "查询对方是否将你加入黑名单")
    @GetMapping("/queryIsBlack")
    public Result<String> queryIsBlack(Integer userId, Integer friendId) throws LeadNewsException {
        String res = relationService.queryIsBlack(userId, friendId);
        return Result.ok(res);
    }

    @ApiOperation(value = "查询所有 有备注的用户备注")
    @GetMapping("/queryAllUserFriendRemarks")
    public Result<List<Relation>> queryAllUserFriendRemarks(Integer userId) throws LeadNewsException {
        List<Relation> res = relationService.queryAllUserFriendRemarks(userId);
        return Result.ok(res);
    }


}
